class Rational:
    # 分数的化简
    @staticmethod
    def _gcd(m, n):
        if n == 0:
            m, n = n, m
        while m != 0:
            m, n = n % m, m
        return n

    def __init__(self, mol, den=1):
        if not isinstance(mol, int) or not isinstance(den, int):
            raise TypeError
        if den == 0:
            raise ZeroDivisionError
        sign = 1
        if mol < 0:
            mol, sign = -mol, -sign
        if den < 0:
            den, sign = -den, -sign
        g = Rational._gcd(mol, den)
        self._mol = sign * (mol // g)
        self._den = den // g

    def num(self):
        return self._mol

    def den(self):
        return self._den

    # 实现分数之间的加法操作
    def __add__(self, another):
        den = self._den * another.den()
        num = (self._mol * another.den() + self._den * another.num())
        return Rational(num, den)

    # 实现分数之间的减法操作
    def __sub__(self, another):
        den = self._den * another.den()
        num = (self._mol * another.den() - self._den * another.num())
        return Rational(num, den)

    # 实现分数之间的乘法操作
    def __mul__(self, another):
        return Rational(self._mol * another.num(), self._den * another.den())

    # 实现分数之间的除法操作
    def __floordiv__(self, another):
        if another.num() == 0:
            raise ZeroDivisionError
        return Rational(self._mol * another.den(), self._den * another.num())

    def __str__(self):
        return str(self._mol) + "/" + str(self._den)

    def __


x = Rational(3, 4)
y = Rational(2, 5)
print(x)
